package sit.engreal.leetcode.problems200;

import org.junit.jupiter.api.Assertions;

/**
 * <a href="https://leetcode.cn/problems/house-robber/">198. 打家劫舍</a>
 */
public class LeetCode198 {

    public int rob(int[] money) {
        int[] acc = new int[money.length + 2];
        for (int i = 0; i < money.length; i++) {
            acc[i + 2] = Math.max(acc[i + 1], acc[i] + money[i]);
        }
        return acc[acc.length - 1];
    }

    public static void main(String[] args) {
        final LeetCode198 demo = new LeetCode198();
        Assertions.assertEquals(4, demo.rob(new int[]{1, 2, 3, 1}));
        Assertions.assertEquals(12, demo.rob(new int[]{2, 7, 9, 3, 1}));
    }
}
